<template>
    <div class="net_con_wp">
        <div class="tab_title">
            <span>{{ title }}</span>
            <i class="iconfonMy icon-guanbi" @click="ipcRenderer.send('close-networkcondition')"></i>
        </div>
        <div class="wifi" v-if="title == '网络状况报告'">
            <div class="list">
                <div>最近{{ runnday }}日软件累计运行{{ filterTime(runningTime, 1) }}分钟</div>
                <div>发生行情断线{{ runnCloseNum }}次</div>
                <div>发生网络丢包0次</div>
                <div v-if="runnCloseNum == 0">未发生网络异常</div>
                <div v-else>平均{{ filterTime(runningTime, 2) }}分钟发生一次网络异常</div>
            </div>
            <div class="jielun">结论：网络状况正常</div>
            <div class="ti_shi">
                <input type="checkbox"> 一天只提示一次
            </div>
            <div class="bottom_conent">
                <span class="chakan_fangfa"
                    @click="shell.openExternal('http://db.wenhua.com.cn/loginnews/bandwidth.asp')">点击这里查看解决方法</span>
                <span class="btn" @click="ipcRenderer.send('open-networkdetail')">查看详情</span>
            </div>
        </div>
        <div class="CPU" v-if="title == 'CPU状态报告'">
            <div class="list">
                <div>最近{{ runnday }}日软件累计运行{{ filterTime(runningTime, 1) }}分钟</div>
                <div>CPU使用率超过50%累计{{ cputime }}分钟</div>
            </div>
            <div class="jielun">结论：CPU使用率正常</div>
            <div class="ti_shi">
                <input type="checkbox"> 一天只提示一次
            </div>
            <div class="bottom_conent">
                <span class="chakan_fangfa"
                    @click="shell.openExternal('https://www.wenhua.com.cn/popwin/yxsd.html')">点击这里查看解决方法</span>
                <span class="btn" @click="ipcRenderer.send('open-networkdetail')">查看详情</span>
            </div>
        </div>

    </div>
</template>

<script setup>
const { ref } = require('vue');
const { ipcRenderer, shell } = require('electron');
const runningTime = ref(0)
const runnday = ref(0)
const runnCloseNum = ref(0)
const cputime = ref(localStorage.getItem('cputime') * 1 || 0)

const title = ref('')

ipcRenderer.on('networkcondition-data', async (e, v) => {
    title.value = v
    getrunTime()
})
function getrunTime() {
    let running_Time = localStorage.getItem('runningTime')
    running_Time = running_Time ? JSON.parse(localStorage.getItem('runningTime')) : {}
    for (let i in running_Time) {
        runnday.value++
        runningTime.value += running_Time[i]
    }
    runnCloseNum.value = localStorage.getItem('runclose') || 0
}

function filterTime(v, type) {
    if (type == 1) {
        return parseInt(v / 60)
    }
    if (type == 2) {
        return parseInt(v / 60 / runnCloseNum.value)
    }
}
</script>

<style scoped lang="less">
.net_con_wp {
    background-color: #f0f0f0;
    color: #000;
    height: 360px;
    width: 520px;
    overflow: hidden;

    .tab_title {
        background-color: #ebf6f9;
        color: #000;
        display: flex;
        align-items: center;
        justify-content: space-between;
        line-height: 25px;
        padding-left: 5px;
        -webkit-app-region: drag;

        i {
            -webkit-app-region: no-drag;
            width: 29px;
            height: 25px;
            text-align: center;
        }

        i:hover {
            background-color: #e61123;
            color: #fff;
        }
    }

    .wifi,
    .CPU {
        padding: 10px;

        .list {
            border: 1px solid #ffffff;
            height: 240px;
            overflow-y: scroll;
            line-height: 23px;
            border-bottom-width: 2px;
            border-bottom-color: #0067c0;
        }

        .jielun {
            line-height: 23px;
        }

        .ti_shi {
            display: flex;
            align-items: center;
            padding: 10px 0;

            input {
                margin-right: 5px;
            }
        }

        .bottom_conent {
            display: flex;
            align-items: center;
            justify-content: space-between;

            .chakan_fangfa {
                color: #0000c0;
            }

            .btn {
                background-color: #fdfdfd;
                padding: 0 15px;
                border-radius: 3px;
                border: 1px solid #d0d0d0;
                line-height: 18px;
            }
        }
    }

    .CPU {
        .list {
            border-bottom-width: 1px;
            border-bottom-color: #838383;
        }
    }
}
</style>
